<!--

    Copyright (C) 2015 The Gravitee team (http://gravitee.io)

    Licensed under the Apache License, Version 2.0 (the "License");
    you may not use this file except in compliance with the License.
    You may obtain a copy of the License at

            http://www.apache.org/licenses/LICENSE-2.0

    Unless required by applicable law or agreed to in writing, software
    distributed under the License is distributed on an "AS IS" BASIS,
    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    See the License for the specific language governing permissions and
    limitations under the License.

-->
<form *ngIf="createForm && apiType" [formGroup]="createForm" (submit)="createEndpointGroup()">
  <mat-card>
    <mat-card-content>
      <mat-stepper [linear]="true">
        <mat-step *ngIf="apiType === 'MESSAGE'" state="type" [stepControl]="createForm.get('type')">
          <ng-template matStepperIcon="type">
            <mat-icon svgIcon="gio:edit-pencil"></mat-icon>
          </ng-template>
          <ng-template matStepLabel>Endpoint Group Type</ng-template>
          <api-endpoints-group-selection
            [endpointGroupTypeForm]="endpointGroupTypeForm"
            [apiType]="apiType"
            [requiredQos]="requiredQos"
          ></api-endpoints-group-selection>
          <div class="api-endpoint-group-create__footer">
            <ng-container *ngTemplateOutlet="exitButton"></ng-container>
            <button mat-raised-button type="button" color="primary" [disabled]="createForm.get('type').invalid" matStepperNext>
              Select endpoint group type
            </button>
          </div>
        </mat-step>

        <mat-step state="general" [stepControl]="createForm.get('general')">
          <ng-template matStepperIcon="general">
            <mat-icon svgIcon="gio:edit-pencil"></mat-icon>
          </ng-template>
          <ng-template matStepLabel>General</ng-template>
          <api-endpoint-group-general [generalForm]="generalForm"></api-endpoint-group-general>
          <div class="api-endpoint-group-create__footer">
            <ng-container *ngIf="apiType === 'PROXY'">
              <ng-container *ngTemplateOutlet="exitButton"></ng-container>
            </ng-container>
            <button *ngIf="apiType === 'MESSAGE'" mat-stroked-button type="button" matStepperPrevious>Back</button>
            <button mat-raised-button type="button" color="primary" [disabled]="createForm.get('general').invalid" matStepperNext>
              Validate general information
            </button>
          </div>
        </mat-step>

        <mat-step state="configuration" [stepControl]="createForm.get('configuration')">
          <ng-template matStepperIcon="configuration">
            <mat-icon svgIcon="gio:edit-pencil"></mat-icon>
          </ng-template>
          <ng-template matStepLabel>Configuration</ng-template>
          <gio-banner-info *ngIf="endpointGroupTypeForm.get('endpointGroupType').value !== 'mock'">
            Inherited configuration
            <span gioBannerBody>Endpoints associated to this endpoint group will automatically inherit its configuration.</span>
          </gio-banner-info>
          <gio-banner-info *ngIf="endpointGroupTypeForm.get('endpointGroupType').value === 'mock'">
            Mock endpoint group
            <span gioBannerBody>Configuration is disabled for Mock endpoint groups.</span>
          </gio-banner-info>
          <gio-form-json-schema
            *ngIf="configurationSchema"
            formControlName="configuration"
            [jsonSchema]="configurationSchema"
          ></gio-form-json-schema>
          <gio-form-json-schema
            *ngIf="sharedConfigurationSchema"
            formControlName="sharedConfiguration"
            [jsonSchema]="sharedConfigurationSchema"
          ></gio-form-json-schema>
          <div class="api-endpoint-group-create__footer">
            <button mat-stroked-button type="button" matStepperPrevious>Back</button>
            <button mat-raised-button type="button" color="primary" [disabled]="createForm.invalid" type="submit">
              {{ createButtonText }}
            </button>
          </div>
        </mat-step>
      </mat-stepper>
    </mat-card-content>
  </mat-card>
</form>

<ng-template #exitButton>
  <button mat-stroked-button type="button" (click)="goBackToEndpointGroups()">Exit</button>
</ng-template>
